import Vue from "vue";
import Router from "vue-router";

import Login from "./views/Login.vue";
import Home from "./views/Home.vue";

Vue.use(Router);

var router = new Router({
  routes: [
    { path: "/", redirect: "/login" },
    { path: "/login", component: Login },
    { path: "/home", component: Home }
  ]
});

// import Welcome from "./views/Welcome.vue";

// import User from "./views/User.vue";

// var router = new Router({
//   routes: [
//     {
//       path: "/login",
//       component: Login
//     },
//     {
//       path: "/home",
//       component: Home,
//       redirect: "/welcome",
//       children: [
//         { path: "/users", component: User },
//         { path: "/welcome", component: Welcome }
//       ]
//     }
//   ]
// });
router.beforeEach(function(to, from, next) {
  var token = window.sessionStorage.getItem("token");
  if (token === null && to.path !== "/login") {
    return next("/login");
  }
  next();
});

export default router;
